package com.hopu.petshop.service.impl;

import com.hopu.petshop.dao.UserDAO;
import com.hopu.petshop.entity.User;
import com.hopu.petshop.service.UserService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl2 implements UserService2 {

    @Autowired
    private UserDAO userDAO;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void subtractPoint(Integer id, Integer point) {
        User user = userDAO.selectUserById(id);
        user.setPoint(user.getPoint() - point);
        userDAO.updatePoint(user);
    }
}
